package com.zghhost.codedemo.util;

import java.math.BigDecimal;

/**
 * @author guohua.zhang@zhaopin.com.cn
 * @Date 2019/1/16 11:12
 */
public class ByteUtil {
    public static String toK(long byteLength){
        BigDecimal bl = BigDecimal.valueOf(byteLength);
        return bl.divide(BigDecimal.valueOf(Math.pow(1024,1))).setScale(2,BigDecimal.ROUND_UP)+"K";
    }

    public static String toM(long byteLength){
        BigDecimal bl = BigDecimal.valueOf(byteLength);
        return bl.divide(BigDecimal.valueOf(Math.pow(1024,2))).setScale(2,BigDecimal.ROUND_UP)+"M";
    }

    public static String toG(long byteLength){
        BigDecimal bl = BigDecimal.valueOf(byteLength);
        return bl.divide(BigDecimal.valueOf(Math.pow(1024,3))).setScale(2,BigDecimal.ROUND_UP)+"G";
    }
}
